package com.example.saifly.inPageRecord.score;

import com.example.saifly.inPageRecord.RecordModel.BodyData;
import com.example.saifly.inPageRecord.RecordModel.EnvironmentData;

public class ScoreBodyEnvironment {

    private EnvironmentData environmentData;
    private BodyData bodyData;

    public void ScoreBodyEnvironment()
    {

    }
    public void setEnvironmentData(EnvironmentData environmentData)
    {
        this.environmentData=environmentData;
    }

    public void setBodyData(BodyData bodyData)
    {
        this.bodyData=bodyData;
    }

    public float environmentScore()
    {
        float score=0;

        if(this.environmentData.getPm25()>75||environmentData.getPm25()==0)
        {
            score+=0;
        }
        else if(this.environmentData.getPm25()<=30)
        {
            score+=100*0.6;
        }
        else
        {
            score+=(100-(environmentData.getPm25()-30)*2)*0.6;
        }
        //湿度
        if(environmentData.getHumidity()>=50&&environmentData.getHumidity()<=70)
        {
            score+=100*0.2;
        }
        else if(environmentData.getHumidity()==0)
        {
            score+=0;
        }
        else if(environmentData.getHumidity()>70)
        {
            score+=(100-(environmentData.getHumidity()-70))*0.2;
        }
        else if(environmentData.getHumidity()<50)
        {
            score+=(100-(50-environmentData.getHumidity()))*0.2;
        }
        //温度
        if(environmentData.getTemperature()>=18&&environmentData.getTemperature()<=28)
        {
            score+=100*0.2;
        }
        else if(environmentData.getTemperature()==0)
        {
            score+=0;
        }
        else if(environmentData.getTemperature()==-200)
        {
            score+=0;
        }
        else if(environmentData.getTemperature()>28)
        {
            score+=(100-(environmentData.getTemperature()-28))*0.2;
        }
        else if(environmentData.getTemperature()<18&&environmentData.getTemperature()>=-30)
        {
            score+=(100-(18-environmentData.getTemperature()))*0.2;
        }
        return score;
    }


    public float bodyScore()
    {
        float score=0;

        if(bodyData.getHeartRate()>=60&&bodyData.getHeartRate()<=100)
        {
            score+=100*0.1;
        }
        else if(bodyData.getHeartRate()<30)
        {
            score=0;
        }
        else if(bodyData.getHeartRate()>150)
        {
            score=0;
        }
        else if(bodyData.getHeartRate()>100&&bodyData.getHeartRate()<=150)
        {
            score+=(100-(bodyData.getHeartRate()-100)*2)*0.1;
        }
        else
        {
            score+=(100-(60-bodyData.getHeartRate())*3.3)*0.1;
        }

        //二氧化碳分压 0.1
        if(bodyData.getCarbonPressure()>=35&&bodyData.getCarbonPressure()<=45)
        {
            score+=100*0.1;
        }
        else if(bodyData.getCarbonPressure()>55)
        {
            score+=0;
        }
        else if(bodyData.getCarbonPressure()<25)
        {
            score+=0;
        }
        else if(bodyData.getCarbonPressure()>=45&&bodyData.getCarbonPressure()<=55)
        {
            score+=(100-(bodyData.getCarbonPressure()-45)*10)*0.1;
        }
        else if(bodyData.getCarbonPressure()>=25&&bodyData.getCarbonPressure()<=35)
        {
            score+=(100-(35-bodyData.getCarbonPressure())*10)*0.1;
        }
        //血氧饱和度0.2
        if(bodyData.getBloodOxygen()>=95)
        {
            score+=100*0.2;
        }
        else if(bodyData.getBloodOxygen()<=80)
        {
            score+=0;
        }
        else
        {
            score+=(105-(95-bodyData.getBloodOxygen())*7)*0.2;
        }
        //血压-高压低压0.2
        if(bodyData.getLowBloodPressure()>=65&&bodyData.getLowBloodPressure()<=84)
        {
            score+=100*0.2;
        }
        else if(bodyData.getLowBloodPressure()<50)
        {
            score+=0;
        }
        else if(bodyData.getLowBloodPressure()>=85&&bodyData.getLowBloodPressure()<=89)
        {
            score+=(100-(bodyData.getLowBloodPressure()-85))*0.2;
        }
        else if(bodyData.getLowBloodPressure()>=90&&bodyData.getLowBloodPressure()<=99)
        {
            score+=(80-(bodyData.getLowBloodPressure()-90))*0.2;
        }
        else if(bodyData.getLowBloodPressure()>=100&&bodyData.getLowBloodPressure()<=109)
        {
            score+=(60-(bodyData.getLowBloodPressure()-100)*1.5)*0.2;
        }
        else if(bodyData.getLowBloodPressure()>=110)
        {
            score+=0;
        }
        //bloodOxygenPressure0.2
        if(bodyData.getBloodOxygenPressure()>=80&&bodyData.getBloodOxygenPressure()<=100)
        {
            score+=100*0.2;
        }
        else if(bodyData.getBloodOxygenPressure()>=60&&bodyData.getBloodOxygenPressure()<=80)
        {
            score+=(100-(bodyData.getBloodOxygenPressure()-60))*0.2;
        }
        else if(bodyData.getBloodOxygenPressure()>=40&&bodyData.getBloodOxygenPressure()<=60)
        {
            score+=(80-(bodyData.getBloodOxygenPressure()-60))*0.2;
        }
        else
        {
            score+=0;
        }

        //	bodyTempreture0.2
        if(bodyData.getBodyTemperature()>=36.3&&bodyData.getBodyTemperature()<=37.2)
        {
            score+=100*0.2;
        }

        else if(bodyData.getBodyTemperature()>=37.3&&bodyData.getBodyTemperature()<=38.5)
        {
            score+=(100-(bodyData.getBodyTemperature()-37.3)*20)*0.2;
        }
        else if(bodyData.getBodyTemperature()>=38.6&&bodyData.getBodyTemperature()<=42.0)
        {
            score+=(76-(bodyData.getBodyTemperature()-38.5)*20)*0.2;
        }
        else if(bodyData.getBodyTemperature()>42.0)
        {
            score+=0;
        }
        else if(bodyData.getBodyTemperature()>=35.0&&bodyData.getBodyTemperature()<=36.2)
        {
            score+=(100-(bodyData.getBodyTemperature()-35.0)*20)*0.2;
        }
        else if(bodyData.getBodyTemperature()<35.0)
        {
            score+=0;
        }
        return score;
    }

}
